<?php

class User extends Eloquent {
	/**
	 * The database table used by the model.
	 *
	 * @var string
	 */
	protected $table = 'user';

	/**
	 * Fetches all the matches that the user is a substitute in
	 *
	 * @return Match array
	 */
	public function matchesSub()
    {
        return $this->belongsToMany('Match', 'match_subs', 'userId', 'matchId');
    }
	
	/**
	 * Fetches all the matches that the user is a guest in
	 *
	 * @return Match array
	 */
	public function matchesGuest()
    {
        return $this->belongsToMany('Match', 'match_guests', 'userId', 'matchId')->withPivot('confirmed');
    }
	
	/**
	 * Fetches all the teams that the user is in
	 *
	 * @return Team array
	 */
	public function teams()
    {
        return $this->belongsToMany('Team', 'team_users', 'userId', 'teamId');
    }
	
	/**
	 * Fetches all the groups that the user is in
	 *
	 * @return Group array
	 */
	public function groups()
    {
        return $this->belongsToMany('Group', 'group_users', 'userId', 'groupId');
    }

    /**
	 * Fetches all the matches that the user is an admin of
	 *
	 * @return Match array
	 */
	public function matchesAdmin()
    {
        return $this->hasMany('Match', 'admin_userId', 'id');
    }
	
	/**
	 * Fetches all the groups that the user is an admin of
	 *
	 * @return Group array
	 */
	public function groupsAdmin()
    {
        return $this->hasMany('Group', 'admin_userId', 'id');
    }
}
